package com.realestate.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.mysema.query.BooleanBuilder;
import com.mysema.query.jpa.JPQLQuery;
import com.mysema.query.jpa.impl.JPAQuery;
import com.realestate.constants.ComUnitName;
import com.realestate.constants.RecordStatus;
import com.realestate.model.BrtbCategory;
import com.realestate.model.QBrtbCategory;
import com.trg.dao.jpa.GenericDAOImpl;

@Repository
public class CategoryDaoImpl extends GenericDAOImpl<BrtbCategory, Long> implements CategoryDao{
	
	private static final Logger logger = Logger.getLogger(CategoryDaoImpl.class);
	
	@Override
	@PersistenceContext(unitName = ComUnitName.COM_UNIT)
	public void setEntityManager(EntityManager entityManager) {
		super.setEntityManager(entityManager);
	}
    
    public void insert(BrtbCategory category) {
        persist(category);
    }
 
    public List<BrtbCategory> selectAll() {
    	JPQLQuery query = new JPAQuery(em());
		QBrtbCategory category = QBrtbCategory.brtbCategory;
		
		query.from(category);
		
		BooleanBuilder where = new BooleanBuilder();
		
		where.and(category.recordStatus.eq(RecordStatus.O));
		
		query.where(where);
		
		List<BrtbCategory> categories = query.list(category);
		return categories;
    }
}
